// 引入 react 依赖
import React, { Component } from 'react';
import { connect } from 'react-redux';
import { Text, View, Image, TouchableOpacity, ImageBackground, ScrollView } from 'react-native';

// 引入第三方依赖
import _ from 'lodash';
import pureRender from 'pure-render-decorator';
import { Actions } from 'react-native-router-flux';

// antd 按需加载
import { } from '@ant-design/react-native';

// 引入 处理数据 所需文件

// 引入样式
import Styles from './style.js';

// 引入公用组件
import { } from '../../components/index.js'

// 引入工具包
import { size, ScreenWidth } from '../../util/utils.js'
class AutoImageHeight extends Component {

	static propTypes = {

	}

	constructor(props) {
		super(props)
		this.state = {
			height: 0
		}
	}

	componentDidMount() {
		const { source, width } = this.props
		if (source.uri) {
			Image.getSize(
				source.uri,
				(e) => {
					console.log(e)
				},
				(error) => {
					console.log(error)
				}
			);
		} else {
			this.setState({
				width: width / ScreenWidth * Image.resolveAssetSource(source).width,
				height: width / ScreenWidth * Image.resolveAssetSource(source).height,
			})
		}

	}

	render() {
		const { style, ...props } = this.props
		const { height, width } = this.state
		return (
			<View style={{}}>
				<Image
					resizeMode='cover'
					{...props}
					onLayout={this.onLayout}
					onLoad={this.onLoad}
					onLoadEnd={this.onLoadEnd}
					onLoadStart={this.onLoadStart}
					onError={this.onError}
					style={[style, {
						width,
						height
					}]}
				/>
			</View>
		)
	}
}

export default pureRender(AutoImageHeight)
